﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;
using WpfAnimation.Helpers;
using WpfAnimation.Models;

namespace WpfAnimation.ViewModels
{
    public class MainVM:ViewModelBase
    {
        private ObservableCollection<NavigateMenuModel> _navigateMenuModelList;

        public ObservableCollection<NavigateMenuModel> NavigateMenuModelList
        {
            get { return _navigateMenuModelList; }
            set { _navigateMenuModelList = value; }
        }
        private NavigateMenuModel _navigateMenuItem;
        /// <summary>
        /// 当前选中
        /// </summary>
        public NavigateMenuModel NavigateMenuItem
        {
            get { return _navigateMenuItem; }
            set
            {
                _navigateMenuItem = value;
                this.NotifyPropertyChange("NavigateMenuItem");
            }
        }
        private object _controlPanel;
        /// <summary>
        /// 更换右侧面板
        /// </summary>
        public object ControlPanel
        {
            get { return _controlPanel; }
            set
            {
                _controlPanel = value;
                this.NotifyPropertyChange("ControlPanel");
            }
        }
        public MainVM()
        {
            NavigateMenuModelList = new ObservableCollection<NavigateMenuModel>();
            foreach (EnumAnimation menuEnum in Enum.GetValues(typeof(EnumAnimation)))
            {
                NavigateMenuModelList.Add(new NavigateMenuModel { Name = menuEnum.ToString() });
            }

            MenuItemSelection(NavigateMenuModelList[0].Name);
            NavigateMenuModelList.Add(new NavigateMenuModel { Name = "持续更新中" });

        }
        public ICommand MenuSelectionChangedCommand => new RelayCommand(obj =>
        {
            if (obj == null) return;
            var model = obj as NavigateMenuModel;
            MenuItemSelection(model.Name);
        });

        public ICommand CloseCommand => new RelayCommand( obj => 
        {
            //Environment.Exit(0);
            Application.Current.MainWindow.Close();
        });


        void MenuItemSelection(string _menuName)
        {
            EnumAnimation flag;
            if (!Enum.TryParse<EnumAnimation>(_menuName, true, out flag))
                return;
            var menuEnum = (EnumAnimation)Enum.Parse(typeof(EnumAnimation), _menuName,true);
            switch (menuEnum)
            {
                case EnumAnimation.BorderAnimation:
                    ControlPanel = new BorderAnimation();
                    break;

                case EnumAnimation.LoadingAnimation:
                    ControlPanel = new LoadingAnimation();
                    break;
                case EnumAnimation.ProgressAnimation:
                    ControlPanel = new ProgressAnimation();
                    break;
                default:
                    break;
            }
        }



     }
}
